package com.ask.initer;

import com.ask.entity.Shop;
import com.ask.service.businessService.IShopService;
import com.ask.service.utilService.BloomFilterService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.stream.Collectors;

@Component
@Slf4j
public class BloomFilterInitializer implements CommandLineRunner {

    @Autowired
    private BloomFilterService bloomFilterService;

    @Autowired
    private IShopService shopService;

    @Override
    public void run(String... args) throws Exception {
        List<Long> ids = shopService.list().stream()
                .map(Shop::getId)
                .collect(Collectors.toList());

        for (Long id : ids) {
            bloomFilterService.add(id);
        }
        log.info("布隆过滤器赋值完成， ids集合：{}", ids);
    }
}
